package com.example.system.dao;

import com.example.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

/**
 * author: adnaan
 * create: 2023-11-01 20:16
 * Description:
 */
@Component
public class SysUserDao {

    @Autowired
    private MongoTemplate mongoTemplate;

    public SysUser get(Query query) {
        return mongoTemplate.findOne(query, SysUser.class);
    }
    public SysUser findByUsername(String username) {
        Criteria criteriaName = Criteria.where("username").is(username);
        Criteria orCriteria = new Criteria();
        orCriteria.orOperator(criteriaName);
        Query query = new Query(orCriteria);
        SysUser sysUser = get(query);
        return sysUser;
    }
}
